home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
com
/
othernet
/
fidonet
/
checktic
/
checktic.c
next >
Wrap
C/C++ Source or Header
|
1994-10-04
|
7KB
|
187 lines
/*******************************************************************************/
/* */
/* CHECKTIC */
/* */
/* workaround for the buggy CRC-checksum-compare-function */
/* in TICKer-ST v.1.04beta from Rayko Balun */
/* */
/* Author: Markus Fischer */
/* */
/* started: 25.09.1994 */
/* */
/* changed: 1.10.1994: now all leading zeros in the crc-checksum will be */
/* removed (although such TIC-files haven't been seen here)*/
/* translated comments from german to english */
/* 4.10.1994: bugfix: check for trailing backslash pointed to wrong */
/* position in the parameter-string */
/* */
/* -> inbound_path: path to folder containing the TIC-files which should be */
/* searched for CRC-checksums with leading zero */
/* */
/* <- returnvalue: 0 - program termination without error, but: */
/* - big TIC-files (> 64KB) have not been searched */
/* - no TIC-files have been found */
/* 1 - incorrect number of parameters or parameter too long */
/* 2 - insufficient memory for internal buffer available */
/* */
/* Limitations: - parameter <inbound_path> will not be checked for validation */
/* or existence */
/* - Program works with internal buffer of static size (64KB) */
/* to examine TIC-files in memory. But TIC-files of that size */ Allerdings duerften so grosse TIC-Files eher selten */
/* seem very rare to me. */
/* */
/*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ext.h>
#include <string.h>
#define bufsize 64*1024L
struct ffblk fblock;
int lastentry; /* result of search for TIX-file */
size_t pathlength; /* Pathlength */
char inboundpath[128]; /* Path from parameter, if needed with
additonal terminating backslash */
char searchpattern[128]; /* Pathline with search-pattern added */
char filename[128]; /* complete path with filename */
char *p; /* pointer at begin of the buffer */
char *crcpos; /* pointer at the begin of the search
pattern in the buffer */
size_t counter; /* number of chars read into buffer */
FILE *fp;
char pattern[] = "\nCRC "; /* search pattern for the CRC-line in
TIC-file */
size_t offset; /* length of the search pattern */
main (int argc, char *argv[])
{
printf ("CheckTIC v.1.0.1 - workaround for TICKer-ST v. 1.04beta from Rayko Balun\n");
printf ("Copyright 1994 by Markus Fischer. All rights reserved.\n");
printf ("Compiled on %s at %s with PureC v.1.1\n\n",__DATE__,__TIME__);
/* no parameter or more than one? */
if (argc != 2)
{
printf ("ERROR: call program 'checktic.ttp <inbound_path>'\n");
return (1);
}
/* path-parameter to TIC-files too long (128 chars minus 12 chars) */
if ((pathlength = strlen (argv[1])) > 116)
{
printf ("ERROR: parameter <inbound_path> too long\n");
return (1);
}
strcpy (inboundpath,argv[1]);
if (inboundpath[pathlength-1] != '\\')
{
strcat (inboundpath, "\\"); /* append missing backslash */
pathlength+=2;
if (pathlength > 116)
{
printf ("ERROR: parameter <inbound_path> too long\n");
return (1);
}
}
/* create search-pattern */
strcpy (searchpattern,inboundpath);
strcat (searchpattern,"*.TIC");
/* search TIC-files */
if ((lastentry = findfirst (searchpattern,&fblock,0)) != 0)
{
printf ("No TIC-files found\n");
return (0);
}
/* reserve static buffer for TIC-file */
if ((p = (char *) malloc (sizeof (char)* bufsize)) == NULL)
{
printf ("ERROR: insufficient memory\n");
return (2);
}
offset = strlen (pattern); /* offset from start of search-
pattern to next char */
while (!lastentry)
{
/* is TIC-file bigger than reserved buffer? */
if (fblock.ff_fsize > bufsize)
{
printf ("%s too large for buffer - CRC-check skipped\n",fblock.ff_name);
}
else
{
/* create complete pathline */
strcpy (filename,inboundpath);
strcat (filename,fblock.ff_name);
/* read file into buffer */
if ((fp = fopen (filename,"r")) != NULL)
{
counter = fread (p, sizeof (char), fblock.ff_fsize, fp);
fclose (fp);
p[counter+1] = '\0'; /* restrict buffer at the end */
/* look for line with CRC-checksum in buffer */
if ((crcpos = strstr (p, pattern)) != NULL)
{
/* If the checksum starts with leading zero,
TICKer-ST reports a checksum-error
-> "workaround": remove the zero from the TIC-file */
/* examine the char following the search-pattern being the "offending" zero */
if (crcpos[offset] == '0')
{
/* move all chars behind the leading zero one
one char forward until no leading zeros are found
and rewrite the file afterwards */
while (crcpos[offset] == '0')
{
strcpy (crcpos+offset*sizeof(char),crcpos+(offset+1)*sizeof(char));
counter--;
}
if ((fp = fopen (filename,"w")) != NULL)
{
fwrite (p, sizeof (char), counter * sizeof (char), fp);
fclose (fp);
printf ("%s: CRC-checksum adjusted\n",fblock.ff_name);
}
else
printf ("Couldn't rewrite %s - will lead to CRC-error when running TICKer-ST\n",fblock.ff_name);
}
}
else
{
printf ("%s contains no CRC-line!\n",fblock.ff_name);
}
}
else
{
printf ("Couldn't open %s - CRC-check skipped\n",fblock.ff_name);
}
}
lastentry = findnext (&fblock); /* is there another TIC-file? */
}
free (p); /* release buffer */
return (0);
}